﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NeuralNetworks.Networks;
using NeuralNetworks.Learning;
using NeuralNetworks.ActivationFunctions;
using NeuralNetworks.Layers;
using NeuralNetworks.Neurons;
using NeuralNetworks;

namespace Ikons
{
    class Program
    {
        static void Main(string[] args)
        {

            ActivationNetwork n = new ActivationNetwork(3, 1, 1, new int[1]{3}, new LogisticFunction());
            DeltaRuleLearning learning = new DeltaRuleLearning(n);
            bool bias = true;
            if (!bias)
            {
                for (int i = 0; i < n.LayersCount; i++)
                {
                    for (int j = 0; j < n[i].NeuronsCount; j++)
                    {
                        n[i][j].BiasEnabled = 1.0;
                    }
                }
            }
            learning.LearningRate = 0.9;
            double[][] inputs = new double[8][] { new double[] {0,0,0},
                                                    new double[] {0,0,1},
                                                    new double[] {0,1,0},
                                                    new double[] {0,1,1},
                                                    new double[] {1,0,0},
                                                    new double[] {1,0,1},
                                                    new double[] {1,1,0},
                                                    new double[] {1,1,1},
            };
            double[][] outputs = new double[8][] {
                                                new double[]{0},
                                                new double[]{1},
                                                new double[]{1},
                                                new double[]{0},
                                                new double[]{1},
                                                new double[]{0},
                                                new double[]{0},
                                                new double[]{1}
            };

            for (int i = 0; i < 1000; i++)
            {
                Console.WriteLine(learning.RunEpoch(inputs, outputs));
            }

            Console.WriteLine("Wagi");
            ActivationLayer last = n[n.LayersCount - 1];
            for (int i = 0; i < last.NeuronsCount; i++)
            {
                ActivationNeuron neuron = last[i];
                Console.WriteLine(neuron.BiasWeight);
                foreach (Connection c in neuron.Inputs)
                {
                    Console.WriteLine(c.Weight);
                }
                Console.WriteLine("============");
            }

            for (int i = 0; i < inputs.Length; i++)
            {
                double[] output = n.Compute(inputs[i]);
                for (int j = 0; j < outputs[0].Length; j++)
                {
                    Console.Write(output[j]);
                    Console.Write(" ");
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
    }
}
